package com.woniu.aopdemo;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 切面类，定义通知
 *
 * @author WenXin
 * @version 1.0
 * @description: TODO
 * @date 2022/8/22 16:58
 */
public class MyAspect implements MethodInterceptor {
    //重写方法
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        checkPermission();//前置通知
        if ("findAll".equals(invocation.getMethod().getName())) {
            System.out.println("是findAll方法");
        }
        //执行对应方法
        Object proceed = invocation.proceed();
        commitTransaction();//后置通知
        return proceed;
    }

    //前置通知
    public void checkPermission() {
        System.out.println("开启权限检查，有权限就放行！");
    }

    //后置通知
    public void commitTransaction() {
        System.out.println("模拟事务提交");
    }
}
